package carmesi.webprovider;

import java.io.File;
import java.io.IOException;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.modules.web.api.webmodule.ExtenderController;
import org.netbeans.modules.web.api.webmodule.WebModule;
import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider;
import org.netbeans.modules.web.spi.webmodule.WebModuleExtender;
import org.openide.filesystems.FileObject;

/**
 *
 * @author Victor
 */
public class CarmesiWebFrameworkProvider extends WebFrameworkProvider{
    static String carmesiResource="META-INF/services/javax.annotation.processing.Processor";

    public CarmesiWebFrameworkProvider() {
        super("Carmesi", "Adds support for Carmesi");
    }

    @Override
    public boolean isInWebModule(WebModule wm) {
        return isCarmesiInWebModule(wm);
    }
    
    public static boolean isCarmesiInWebModule(WebModule wm){
        try{
            ClassPath classPath = ClassPath.getClassPath(wm.getWebInf(), ClassPath.COMPILE);
            FileObject resource = classPath.findResource(carmesiResource);
            return resource != null ? resource.asText().contains("Carmesi") : false;
        }catch(IOException ex){
            throw new RuntimeException(ex);
        }
    }

    @Override
    public File[] getConfigurationFiles(WebModule wm) {
        return new File[0];
    }

    @Override
    public WebModuleExtender createWebModuleExtender(WebModule wm, ExtenderController controller) {
        return new CarmesiWebModuleExtender(wm);
    }
    
}
